{%extends "admin/base.html" %}

{%block breadcrumb%}
<ol class="breadcrumb">
    <li class="breadcrumb-item"><a href="/admin">首页</a></li>
    <li class="breadcrumb-item"><a href="/admin/system/user/index">系统管理员管理</a></li>
    <li class="breadcrumb-item active">{{title}}</li>
</ol>
{%endblock%}

{%block main%}
<div class="row">
    <div class="col-12">
        <div class="card">
            <form class="form-horizontal">
                <div class="card-body">
                    <div class="form-group row">
                        <label for="username" class="col-sm-2 col-form-label">
                            登录账号
                            <span class="text-danger">*</span>
                        </label>
                        <div class="col-sm-10">
                            <input type="input" class="form-control" id="username" name="username" autocomplete="false" {%if info.username %}value="{{info.username}}" {%endif%}>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="nickname" class="col-sm-2 col-form-label">昵称</label>
                        <div class="col-sm-10">
                            <input type="input" class="form-control" id="nickname" name="nickname" autocomplete="false" {%if info.nickname %}value="{{info.nickname}}" {%endif%}>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="password" class="col-sm-2 col-form-label">
                            登录密码
                            {%if info.id > 0%}
                            {%else%}
                            <span class="text-danger">*</span>
                            {%endif%}
                        </label>
                        <div class="col-sm-10">
                            <input type="input" class="form-control" id="password" name="password" autocomplete="false">
                            {%if info.id > 0%}
                            <span class="form-text">不输入密码值，则不修改密码</span>
                            {%endif%}
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="parameter" class="col-sm-2 col-form-label">权限组</label>
                        <div class="col-sm-10">
                            <div class="row">
                                {%for v in role%}
                                <div class="col-sm-6 col-md-3 col-xl-2">
                                    <div class="icheck-success d-inline">
                                        <input type="checkbox" name="role[]" id="role:{{v.id}}" value="{{v.id}}" {%if v.own==true%}checked{%endif%}>
                                        <label for="role:{{v.id}}">{{v.title}}</label>
                                    </div>
                                </div>
                                {%endfor%}
                            </div>
                        </div>
                    </div>
                    {%if info.id > 0%}
                    <input type="hidden" name="id" value="{{info.id}}">
                    {%endif%}
                </div>
                <div class="card-footer">
                    <button type="submit" class="btn btn-primary">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
{%endblock%}

{%block js%}
<script>
    $(function () {
        $('form').submit(function (e) {
            e.preventDefault();
            $.post('{{ url("") }}', $('form').serialize(), function (res) {
                _msg = ('msg' in res) ? res.msg : '未知错误';
                if (!('code' in res) || res.code != 0) {
                    toastr.error(_msg);
                } else {
                    toastr.success('保存成功');

                    setTimeout(() => {
                        window.location.href = '{{ url("index") }}';
                    }, 3000);
                }
            });
        });
    });
</script>
{%endblock%}